package com.roc.steelend.controller;


import com.auth0.jwt.interfaces.DecodedJWT;
import com.roc.steelend.controller.vo.account.*;
import com.roc.steelend.controller.vo.returnformat.ReturnMsg;
import com.roc.steelend.controller.vo.returnformat.ReturnMsgForTable;
import com.roc.steelend.service.AccountService;
import com.roc.steelend.util.JWTUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "账务功能接口")
@CrossOrigin
public class AccountController {

    @Autowired
    private AccountService accountService;

    @PostMapping("/v1/post/account/common")
    @ApiOperation(value = "提交普通账务的post接口", notes = "需要一个普通账务的接收类")
    public Boolean postAccountCommon(@RequestBody AccountCommonReception accountCommonReception, HttpServletRequest request) {
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();

        return accountService.addAccountCommon(accountCommonReception, Integer.valueOf(employeeIdAsString));
    }

    @PostMapping("/v1/post/account/special/buy")
    @ApiOperation(value = "提交特殊账务buy的post接口", notes = "需要一个特殊账务buy的接收类")
    public ReturnMsg postAccountSpecialBuy(@RequestBody AccountSpecialBuyReception accountSpecialBuyReception, HttpServletRequest request) {
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();
     return    accountService.postAccountSpecialBuy(accountSpecialBuyReception,Integer.valueOf(employeeIdAsString));

    }

    @PostMapping("/v1/post/account/special/sale")
    @ApiOperation(value = "提交特殊账务sale的post接口", notes = "需要一个特殊账务sale的接收类")
    public ReturnMsg postAccountSpecialSale(@RequestBody AccountSpecialSaleReception accountSpecialSaleReception, HttpServletRequest request) {
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();
        return    accountService.postAccountSpecialSale(accountSpecialSaleReception,Integer.valueOf(employeeIdAsString));
    }

    @PostMapping("/v1/post/account/special/kaiping")
    @ApiOperation(value = "提交特殊账务kaiping的post接口", notes = "需要一个特殊账务kaiping的接收类")
    public ReturnMsg postAccountSpecialkaiping(@RequestBody AccountSpecialKaipingReception accountSpecialKaipingReception, HttpServletRequest request) {
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();
        return  accountService.postAccountSpecialKaiping(accountSpecialKaipingReception,Integer.valueOf(employeeIdAsString));
    }


    @PostMapping("/v1/select/account/data")
    @ApiOperation(value = "采购账务接口(ps:特殊情况使用post,但不修改数据!!!)", notes = "采购账务接口(ps:特殊情况使用post,但不修改数据!!!)")
    public ReturnMsgForTable selectAccountData(@RequestBody FindAccountReception findAccountReception) {

        System.out.println(findAccountReception);

        ReturnMsgForTable returnMsgForTable = new ReturnMsgForTable();
        returnMsgForTable.setCurrenPage(findAccountReception.getCurrentPage());
        returnMsgForTable.setObjectList(accountService.selectAccountData(findAccountReception));
        returnMsgForTable.setTotal(accountService.selectAccountDataCount(findAccountReception));
        return  returnMsgForTable;
    }

    @GetMapping("/v1/show/pay/revenue/sum/this/day")
    @ApiOperation(value = "首页上展示当天的收入支出情况")
    public Map<String, BigDecimal> showPayRevenueSumThisDay(){

       return accountService.showPayRevenueSumThisDay();

    }
}
